<?php
    extract(extractPost(), EXTR_PREFIX_ALL, 'c');
    if(isset($c_column_id)){
         //$numOfColumnCards = R::count( 'card', ' column_id = ? ', [ $c_column_id ] );
         
         $column = R::load('column', $c_column_id);
         if($column->id == 0){
             jsonErrorDie("Column with provided id does not exist.");
         }
         
         if(count($column->ownCardList) > 0){
             jsonErrorDie("You are not allowed to delete selected column, because it contains one or more card.");
         }
         else{
             $name = $column->name;
             $subcolumns = R::getAll( 'SELECT * FROM `column` WHERE `board_id` = ? AND `project_id` = ? AND `name` = ? ORDER BY position ASC', array($column->board_id, $column->project_id, $column->name));
             if(count($subcolumns)==1){
                 $column->subcolumn = NULL;
                 R::store($column);
                 jsonSuccessDie("msg", "Subcolumn successfully deleted!");
             }
             else{
                R::trash($column);
                jsonSuccessDie("msg", "Column successfully deleted!");
             }
             
        }
        
    }
